<?php
/**
 *
 * @revision:   $Id: helper.php 40 2011-06-12 14:56:15Z agbiggora@gmail.com $
 * @package	    Joomla!
 * @since       {SINCE}
 * @subpackage	AG Social Bookmarks
 * @version     {PROJECTVERSION}
 * @desc        The AG Social Bookmarks module is based on the Sexy Bookmarks Plugin for Wordpress
 *              originaly designed and coded by Josh Jones http://www.eight7teen.com
 * @copyright	Copyright © 2010-{PROJECTYEAR} Alexey Gordeyev IK. All rights reserved.
 * @license		GNU General Public License v2.0
 * @author		ALEXEY GORDEYEV IK
 * @author mail	admin@gordejev.lv
 * @website		www.gordejev.lv
 *
 * CODE GENERATED BY: ALEXEY GORDEYEV IK CODE GENERATOR
 * HTTP://WWW.AGJOOMLA.COM/
 *
 * The module methods
 * -------------------------------
 * makeBookmarks( &$article, &$params, $limitstart='')
 * checkCategories(&$article, $params)
 * searchBookmarkTag($text)
 * searchAntiBookmarkTag(&$article)
 * fetchBackground($params)
 * fetchSexyHTML(&$article,$params)
 * fetchHTMLSnippet($class, $url, $title, $params)
 * constructFrontpageUrl(&$article)
 * deleteBookmarkTag($text)
 * getShortUrl($url)
 * _findItem($needles)
 *
 */

//no direct access
defined('_JEXEC') or die('Direct Access to this location is not allowed.');

define('SOCIAL_URL', JURI::base()."modules/mod_agsocialbookmarks");
define('SOCIAL_VER', '{PROJECTVERSION}');

/**
 *
 * AG Social Bookmarks Helper Class
 * @since {SINCE}
 *
 */

class ModAGSocialBookmarksHelper
{

   /**
    * Adds the plugin to the required point
    *
    * @param  string $article
    * @param  array $params
    * @param  integer $limitstart
    * @return mixed
    */
   function makeBookmarks( &$article, &$params, $limitstart='') {

      $doc =& JFactory::getDocument();

      if($params->get('add_css') == 1) {
         $doc->addStyleSheet(SOCIAL_URL."/css/".$params->get('css_file').".css?img=25");
      }

      // Not yet available
      //$doc->addScript(SOCIAL_URL."/sexybookmarks.js");
      JHTML::_('behavior.tooltip');
      
      $socialbookmarks = "";

      if(!self::checkCategories($article,$params)) return;

      if($params->get('manual') != 1 && !self::searchAntiBookmarkTag($article)) {
         $article->text = self::deleteBookmarkTag($article->text);
         if($params->get('article') == 1 && JRequest::getVar('view') == 'article') {
            $socialbookmarks = self::fetchSocialHTML($article,$params);
         } elseif($params->get('frontpage') == 1 && JRequest::getVar('view') == 'frontpage') {
            $socialbookmarks = self::fetchSocialHTML($article,$params);
         } elseif($params->get('blog') == 1 && JRequest::getVar('layout') == 'blog') {
            $socialbookmarks = self::fetchSocialHTML($article,$params);
         } elseif($params->get('newsfeed') == 1 && JRequest::getVar('view') == 'newsfeed') {
            $socialbookmarks = self::fetchSocialHTML($article,$params);
         } elseif($params->get('category') == 1 && JRequest::getVar('view') == 'category') {
            $socialbookmarks = self::fetchSocialHTML($article,$params);
         } elseif($params->get('k2items') == 1 && JRequest::getVar('view') == 'item') {
            $socialbookmarks = self::fetchSocialHTML($article,$params);
         } elseif($params->get('k2categories') == 1 && JRequest::getVar('view') == 'itemlist') {
            $socialbookmarks = self::fetchSocialHTML($article,$params);
         } elseif($params->get('voditems') == 1 && JRequest::getVar('view') == 'video') {
            $socialbookmarks = self::fetchSocialHTML($article,$params);
         } elseif($params->get('vodcategories') == 1 && JRequest::getVar('controller') == 'categories') {
            $socialbookmarks = self::fetchSocialHTML($article,$params);
         } elseif($params->get('vodcontainers') == 1 && JRequest::getVar('view') == 'conteiner') {
            $socialbookmarks = self::fetchSocialHTML($article,$params);
         } elseif($params->get('vodcontainers') == 1 && JRequest::getVar('view') == 'conteiner') {
            $socialbookmarks = self::fetchSocialHTML($article,$params);
         } elseif($params->get('kunenacategories') == 1 && JRequest::getVar('func') == 'showcat') {
            $socialbookmarks = self::fetchSocialHTML($article,$params);
         } else {
            return;
         }
      }
      return $socialbookmarks;
   }

   /**
    * Newsfeed categories category
    * Category check. Is the articles category allowed to print
    * the bookmarks menu
    *
    * @param  string $article
    * @return bool
    */
   function checkCategories(&$article, $params) {
      if($params->get('include_cat') == "") return true;

      $include_array = explode(",", $params->get('include_cat'));

      if(in_array($article->catid, $include_array)) {
         return true;
      } else {
         return false;
      }
   }

   /**
    * Manually insertion of the Bookmarks Menu
    *
    * @param  object $article
    * @return object
    */
   function searchBookmarkTag($text) {
      $searchtag = "{sexybookmark}";

      if(substr_count($text, $searchtag) >= 1) {
         $text = $text.self::fetchSocialHTML($article);
      } else {
         $text = $text;
      }

      $text = self::deleteBookmarkTag($text);
      return $text;
   }

   /**
    * Check for existing {nosexybookmark} in articles
    *
    * @param  object $article
    * @return bool
    */
   function searchAntiBookmarkTag(&$article) {
      $searchtag = "{nosexybookmark}";
      if(substr_count($article->text, $searchtag) >= 1) {
         $article->text = self::deleteAntiBookmarkTag($article->text);
         return true;
      }
      return false;
   }

   /**
    * Fetches the required background image
    * @param  array $params
    * @return string
    */
   function fetchBackground($params) {
      if($params->get('css_file') == 'sexy') {
         if($params->get('bgimg') == 'caring') {
            return " social-bookmarks-bg-caring";
         } elseif($params->get('bgimg') == 'sexy') {
            return " social-bookmarks-bg-sexy";
         } elseif($params->get('bgimg') == 'wealth') {
            return " social-bookmarks-bg-wealth";
         } elseif($params->get('bgimg') == 'care-old') {
            return " social-bookmarks-bg-caring-old";
         } elseif($params->get('bgimg') == 'love') {
            return " social-bookmarks-bg-love";
         } else {
            return "";
         }
      } else {
         return "";
      }
   }

   /**
    * Core function to add the Sexy Bookmarks menu to the article
    *
    * @param object $article
    * @return mixed
    */
   function fetchSocialHTML(&$article,$params) {

      $echo_bookmarks = false;

      $j_config =& JFactory::getConfig();

      if($params->get('article') == 1 && JRequest::getVar('view') == 'article') {
         $url =& JFactory::getURI();
         $perms = $url->toString();
         $perms = str_replace( '&amp;', '&', $perms );
         $echo_bookmarks = true;
      } else {
         $user =& JFactory::getUser();
         if ($article->access <= $user->get('aid', 0)) {
            jimport('joomla.application.component.helper');
            $perms = JRoute::_(self::constructFrontpageUrl($article), false, -1);
            $echo_bookmarks = true;
         } else {
            $echo_bookmarks = false;
         }
      }

      if($j_config->getValue('config.sef') != 1) $perms = urlencode($perms);

      $title = urlencode($article->title);
      $title = str_replace('%3A',':',$title);
      $title = str_replace('%3F','?',$title);
      $title = str_replace('%C3%B9','�',$title);
      $title = str_replace('%C3%A0','�',$title);
      $title = str_replace('%C3%A8','�',$title);
      $title = str_replace('%C3%AC','�',$title);
      $title = str_replace('%C3%B2','�',$title);

      $short_title = substr($title, 0, 60)."...";

      $mail_subject = urlencode(substr($title, 0, 60)."...");
      $mail_subject = str_replace('+','%20',$mail_subject);
      $mail_subject = str_replace("&#8217;","'",$mail_subject);

      $social_content = urlencode(strip_tags(substr($article->text, 0, 220)."[..]"));
      //$social_content = urlencode(substr(strip_tags(strip_shortcodes(get_the_content())),0,300));
      $social_content = str_replace('+','%20',$social_content);
      $social_content = str_replace("&#8217;","'",$social_content);

      $post_summary = stripslashes($social_content);

      $social_teaser = strip_tags(substr($article->text, 0, 250)."[..]");
      // $social_teaser = $social_content;
      $strip_teaser = stripslashes($social_teaser);

      $site_name = $title;
      $mailer = JText::_("Email from Social Bookmarks module!").'%0D%0Awww.agjoomla.com';

      if($params->get('twitter') == 1 && $params->get('twittid') != "") {
         $short_url = self::getShortUrl($perms,$params);
         $post_by = "RT+@".$params->get('twittid').":+";
      }

      if ($params->get('twittley') == 1 && $article->metakey != '') {
         $twittley_cat = $params->get('twittcat');
         $twittley_tags = $article->metakey;
      } elseif($params->get('twittley') == 1 && $params->get('twittcat') != '') {
         $twittley_cat = $params->get('twittcat');
         $twittley_tags = $params->get('defaulttags');
      }
      $style = '';
      if($params->get('css_file') != 'single') {
         $style = 'style="'.$params->get('xtrastyle').'"';
      }
      $socials = "\n".'<div class="social-bookmarks'.self::fetchBackground($params).'" '.$style.' id="social-bookmarks"><ul id="socials" class="socials">'.
      ($params->get('scriptstyle') == 1 ? self::fetchHTMLSnippet("social-scriptstyle", "http://scriptandstyle.com/submit?url=".$perms."&amp;title=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_SUBMIT_THIS_TO"),JText::_("Script Style"),$params) : '').
      ($params->get('blinklist') == 1 ? self::fetchHTMLSnippet("social-blinklist", "http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=".$perms."&amp;Title=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("Blinklist"),$params) : '').
      ($params->get('delicious') == 1 ? self::fetchHTMLSnippet("social-delicious", "http://del.icio.us/post?url=".$perms."&amp;title=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("del.icio.us"),$params) : '').
      ($params->get('digg') == 1 ? self::fetchHTMLSnippet("social-digg", "http://digg.com/submit?phase=2&amp;url=".$perms."&amp;title=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("Digg"),$params) : '').
      ($params->get('reddit') == 1 ? self::fetchHTMLSnippet("social-reddit", "http://reddit.com/submit?url=".$perms."&amp;title=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("Reddit"),$params) : '').
      # пересмотреть
      ($params->get('stumpleupon') == 1 ? self::fetchHTMLSnippet("social-stumbleupon", "http://www.stumbleupon.com/submit?url=".$perms."&amp;title=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("StumbleUpon"),$params) : '').
      ($params->get('technorati') == 1 ? self::fetchHTMLSnippet("social-technorati", "http://technorati.com/faves?add=".$perms, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("Technorati"),$params) : '').
      ($params->get('mixx') == 1 ? self::fetchHTMLSnippet("social-mixx", "http://www.mixx.com/submit?page_url=".$perms."&amp;title=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("Mixx"),$params) : '').
      ($params->get('myspace') == 1 ? self::fetchHTMLSnippet("social-myspace", "http://www.myspace.com/Modules/PostTo/Pages/?u=".$perms."&amp;t=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_POST_THIS_ON"),JText::_("MySpace"),$params) : '').
      ($params->get('designfloat') == 1 ? self::fetchHTMLSnippet("social-designfloat", "http://www.designfloat.com/submit.php?url=".$perms."&amp;title=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_SUBMIT_THIS_TO"),JText::_("DesignFloat"),$params) : '').
      ($params->get('facebook') == 1 ? self::fetchHTMLSnippet("social-facebook", "http://www.facebook.com/share.php?u=".$perms."&amp;t=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("Facebook"),$params) : '').
      ($params->get('twitter') == 1 && $params->get('twittid') != "" && $short_url != "" ? self::fetchHTMLSnippet("social-twitter", 'http://www.twitter.com/home?status='.$post_by.'+'.$short_title.'+-+'.$short_url, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("Twitter"),$params) : '').
      ($params->get('devmarks') == 1 ? self::fetchHTMLSnippet("social-devmarks", 'http://devmarks.com/index.php?posttext='.$post_summary.'&amp;posturl='.$perms.'&posttitle='.$title, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("Devmarks"),$params) : '').
      ($params->get('newsvine') == 1 ? self::fetchHTMLSnippet("social-newsvine", "http://www.newsvine.com/_tools/seed&save?u=".$perms."&amp;h=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_SEED_THIS_ON"),JText::_("Newsvine"),$params) : '').
      ($params->get('linkedin') == 1 ? self::fetchHTMLSnippet("social-linkedin", 'http://www.linkedin.com/shareArticle?mini=true&amp;url='.$perms.'&amp;title='.$title.'&amp;summary='.$post_summary.'&amp;source='.$site_name, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("Linkedin"),$params) : '').
      ($params->get('blogger') == 1 ? self::fetchHTMLSnippet("social-blogger", "http://www.blogger.com/blog_this.pyra?t&amp;u=".$perms."&amp;n=".$title.'&amp;pli=1', JText::_("MOD_AGSOCIALBOOKMARKS_ADD_THIS_TO"),JText::_("Blogger"),$params) : '').
      ($params->get('google') == 1 ? self::fetchHTMLSnippet("social-googlebookmarks", "http://www.google.com/bookmarks/mark?op=add&amp;bkmk=".$perms."&amp;title=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_ADD_THIS_TO"),JText::_("Google Bookmarks"),$params) : '').
      ($params->get('orkut') == 1 ? self::fetchHTMLSnippet("social-orkut", "http://promote.orkut.com/preview?nt=orkut.com&du=".$perms."&amp;tt=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_ADD_THIS_TO"),JText::_("Orkut"),$params) : '').
      ($params->get('googlereader') == 1 ? self::fetchHTMLSnippet("social-googlereader", "http://www.google.com/reader/link?url=".$perms."&amp;title=".$title."&amp;srcUrl=".$perms."&amp;srcTitle=".$title."&amp;snippet=".$social_content, JText::_("MOD_AGSOCIALBOOKMARKS_ADD_THIS_TO"),JText::_("Google Reader"),$params) : '').
      ($params->get('googlebuzz') == 1 ? self::fetchHTMLSnippet("social-googlebuzz", "http://www.google.com/buzz/post?url=".$perms."&amp;imageurl=", JText::_("MOD_AGSOCIALBOOKMARKS_ADD_THIS_TO"),JText::_("Google Buzz"),$params) : '').
      ($params->get('gmail') == 1 ? self::fetchHTMLSnippet("social-gmail", "https://mail.google.com/mail/?ui=2&amp;view=cm&amp;fs=1&amp;tf=1&amp;su=".$title."&amp;body=Link: ".$perms.'%0D%0A%0D%0A----%0D%0A'.$social_content.'%0D%0A'.$mailer, JText::_("MOD_AGSOCIALBOOKMARKS_EMAIL_THIS_VIA"),JText::_("Gmail"),$params) : '').
      ($params->get('yahoomyweb') == 1 ? self::fetchHTMLSnippet("social-yahoomyweb", "http://bookmarks.yahoo.com/myresults/bookmarklet?u=".$perms."&t=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_SAVE_THIS_TO"),JText::_("Yahoo Bookmarks"),$params) : '').
      # http://bookmarks.yahoo.com/myresults/bookmarklet?u=http://a2p.net.ru/wordpress/22/social_bookmarks_runet/&t=Social+Bookmarks+%25D0%25B4%25D0%25BB%25D1%258F+%25D0%25A0%25D0%25A3%25D0%25BD%25D0%25B5%25D1%2582%25D0%25B0
      ($params->get('yahoomail') == 1 ? self::fetchHTMLSnippet("social-yahoomail", "http://compose.mail.yahoo.com/?To=&Body=".$perms."&Subj=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_EMAIL_THIS_VIA"),JText::_("Yahoo! Mail"),$params) : '').
      # http://ru.mail.yahoo.com/?.intl=ru    compose.mail.yahoo.com
      # http://ru.mg4.mail.yahoo.com/neo/launch?.rand=1580060976&action=compose&To=&Subj= &Body=    http://www.gordejev.lv/ru/exiting-extensions/7-modules-joomla/58-agyandexmetrika.html
      ($params->get('yahoobuzz') == 1 ? self::fetchHTMLSnippet("social-yahoobuzz", "http://buzz.yahoo.com/buzz?targetUrl=".$perms.'&amp;submitHeadline='.$title.'&amp;submitSummary='.$strip_teaser, JText::_("MOD_AGSOCIALBOOKMARKS_SAVE_THIS_TO"),JText::_("Yahoo Buzz"),$params) : '').
      //($params->get('email') == 1 ? self::fetchHTMLSnippet("social-mail", 'mailto:?subject='.$mail_subject.'&amp;body='.$strip_teaser.' - '.$perms, JText::_("MOD_AGSOCIALBOOKMARKS_EMAIL_THIS_TO_FRIEND"),$params) : '').
      ($params->get('misterwong') == 1 ? self::fetchHTMLSnippet("social-misterwong", "http://www.mister-wong.com/addurl/?bm_url=".$perms."&amp;bm_description=".$title."&amp;module=sexybookmarks", JText::_("MOD_AGSOCIALBOOKMARKS_ADD_THIS_TO"),JText::_("Mister Wong"),$params) : '').
      ($params->get('izeby') == 1 ? self::fetchHTMLSnippet("social-izeby", "http://izeby.com/add_story.php?story_url=".$perms, JText::_("MOD_AGSOCIALBOOKMARKS_ADD_THIS_TO"),JText::_("Izeby"),$params) : '').
      ($params->get('diigo') == 1 ? self::fetchHTMLSnippet("social-diigo", "http://www.diigo.com/post?url=".$perms."&amp;title=".$title."&amp;desc=".$social_teaser, JText::_("MOD_AGSOCIALBOOKMARKS_POST_THIS_ON"),JText::_("Diigo"),$params) : '').
      ($params->get('tumblr') == 1 ? self::fetchHTMLSnippet("social-tumblr", "http://www.tumblr.com/share?v=3&amp;u=".$perms."&amp;t=".$title."&amp;s=", JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("Tumblr"),$params) : '').
      ($params->get('tipd') == 1 ? self::fetchHTMLSnippet("social-tipd", "http://tipd.com/submit.php?url=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("Tipd"),$params) : '').
      ($params->get('pfbuzz') == 1 ? self::fetchHTMLSnippet("social-pfbuzz", "http://pfbuzz.com/submit?url=".$perms."&amp;title=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("PFBuzz"),$params) : '').
      ($params->get('friendfeed') == 1 ? self::fetchHTMLSnippet("social-friendfeed", "http://www.friendfeed.com/share?title=".$title."&amp;link=".$perms, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("FriendFeed"),$params) : '').
      ($params->get('blogmarks') == 1 ? self::fetchHTMLSnippet("social-blogmarks", "http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=".$perms."&amp;title=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_MARK_THIS_ON"),JText::_("BlogMarks"),$params) : '').
      ($params->get('twittley') == 1 ? self::fetchHTMLSnippet("social-twittley", "http://twittley.com/submit/?title=".$title."&amp;url=".$perms."&amp;desc=".$post_summary."&amp;pcat=".$twittley_cat."&amp;tags=".$twittley_tags, JText::_("MOD_AGSOCIALBOOKMARKS_SUBMIT_THIS_TO"),JText::_("Twittley"),$params) : '').
      ($params->get('fwisp') == 1 ? self::fetchHTMLSnippet("social-fwisp", "http://fwisp.com/submit?url=".$perms, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("Fwisp"),$params) : '').
      ($params->get('bonzobox') == 1 ? self::fetchHTMLSnippet("social-bonzobox", "http://bonzobox.com/toolbar/add?pop=1&amp;u=".$perms.'&amp;t='.$title.'&amp;d='.$social_content, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("BonzoBox"),$params) : '').
      ($params->get('plaxo') == 1 ? self::fetchHTMLSnippet("social-plaxo", "http://www.plaxo.com/?share_link=".$perms, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("Plaxo"),$params) : '').
      ($params->get('sharebrain') == 1 ? self::fetchHTMLSnippet("social-sharebrain", "http://sharebrain.info/?share_link=".$perms, JText::_("MOD_AGSOCIALBOOKMARKS_ADD_THIS_TO"),JText::_("ShareBrain"),$params) : '').
      ($params->get('amazon-wishlist') == 1 ? self::fetchHTMLSnippet("social-amazon-wishlist", "http://www.amazon.com/wishlist/add?u=".$perms."&t=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_ADD_THIS_TO"),JText::_("Amazon"),$params) : '').
      ($params->get('live') == 1 ? self::fetchHTMLSnippet("social-live", "https://office.live.com/sharefavorite.aspx%2f.SharedFavorites??marklet=1&url=".$perms."&title=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("Live"),$params) : '').
      ($params->get('hyves') == 1 ? self::fetchHTMLSnippet("social-hyves", "http://www.hyves.nl/profilemanage/add/tips/?name=".$title."&text=".$perms."&type=12", JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("Hyves"),$params) : '').
      # Russian
      ($params->get('yandex') == 1 ? self::fetchHTMLSnippet("social-yandex", "http://zakladki.yandex.ru/userarea/links/addfromfav.asp?bAddLink_x=1&amp;lurl=".$perms."&amp;lname=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_ADD_THIS_TO"),JText::_("MOD_AGSOCIALBOOKMARKS_YANDEX_RU"),$params) : '').
      ($params->get('memoryru') == 1 ? self::fetchHTMLSnippet("social-memoryru", "http://memori.ru/link/?sm=1&amp;u_data[url]=".$perms."&amp;u_data[name]=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_ADD_THIS_TO"),JText::_("MOD_AGSOCIALBOOKMARKS_MEMORY_RU"),$params) : '').
      ($params->get('100zakladok') == 1 ? self::fetchHTMLSnippet("social-100zakladok", "http://www.100zakladok.ru/save/?bmurl=".$perms."&amp;bmtitle=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_ADD_THIS_TO"),JText::_("MOD_AGSOCIALBOOKMARKS_100_BOOKMARKS_RU"),$params) : '').
      ($params->get('moemesto') == 1 ? self::fetchHTMLSnippet("social-moemesto", "http://moemesto.ru/post.php?url=".$perms."&amp;title=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_ADD_THIS_TO"),JText::_("MOD_AGSOCIALBOOKMARKS_MYPLACE_RU"),$params) : '').
      # NEW
      ($params->get('odnoklassniki') == 1 ? self::fetchHTMLSnippet("social-odnoklassniki", "http://www.odnoklassniki.ru/dk?st.cmd=addShare&st.s=1&st._surl=".$perms, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("MOD_AGSOCIALBOOKMARKS_ODNOKLASSNIKI_RU"),$params) : '').
      ($params->get('draugiem') == 1 ? self::fetchHTMLSnippet("social-draugiem", "http://www.draugiem.lv/say/ext/add.php?url=".$perms."&title=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("MOD_AGSOCIALBOOKMARKS_DRAUGIEM_LV"),$params) : '').
      ($params->get('vkontakte') == 1 ? self::fetchHTMLSnippet("social-vkontakte", "http://vkontakte.ru/share.php?url=".$perms, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("MOD_AGSOCIALBOOKMARKS_VKONTAKTE_RU"),$params) : '').
      ($params->get('livejornal') == 1 ? self::fetchHTMLSnippet("social-livejornal", "http://www.livejournal.com/update.bml?event=".$perms, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),JText::_("MOD_AGSOCIALBOOKMARKS_LIVEJOURNAL_RU"),$params) : '').
      ($params->get('bobrdobr') == 1 ? self::fetchHTMLSnippet("social-bobrdobr", "http://bobrdobr.ru/addext.html?url=".$perms."&title=".$title, JText::_("MOD_AGSOCIALBOOKMARKS_ADD_THIS_TO"),JText::_("BobrDobr"),$params) : '').
      ($params->get('mailru') == 1 ? self::fetchHTMLSnippet("social-mailru", "http://connect.mail.ru/share?share_url=".$perms, JText::_("MOD_AGSOCIALBOOKMARKS_SHARE_THIS_ON"),"Mail.ru",$params) : '').
        '</ul></div>';

      if($echo_bookmarks === true) {
         return $socials;
      } else {
         return;
      }
   }

   /**
    * Builds each single menu element as a HTML list element
    *
    * @param string $class
    * @param string $url
    * @param string $title
    * @return string
    */
   function fetchHTMLSnippet($class, $url, $title, $name, $params) {
      if($params->get('add_nofollow') == 1) {
         $relopt = "nofollow";
      } else {
         $relopt = "";
      }

      if($params->get('open_in_newwindow') == 1) {
         $tarwin = "_blank";
      } else {
         $tarwin = "_self";
      }
      $popup_win = "onclick=\"window.open(this.href, '".$tarwin."', 'scrollbars=yes,menubar=no,left=100,top=100,height=500,width=700,resizable=yes,toolbar=no,location=no,status=no'); return false;\"";
      $html  = "\n";

      if($params->get('css_file') == "boxed") {

         $html .= '<li>';
         $html .= '<a '.$popup_win.' class="editlinktip hasTip"  title="'.$title.'::'.$name.'" href="'.$url.'" rel="'.$relopt.'">';
         $html .= '<div class="social-button '.$class.'"></div>';
         $html .= '<div class="social-share"><span class="social-share-text">'.$title.'</span>';
         $html .= '<span class="social-share-title">'.$name.'</span></div>';
         $html .= '</a>';
         $html .= '</li>';
      }
      else {
         $html .= '<li class="'.$class.'">';
         $html .= '<a '.$popup_win.' class="editlinktip hasTip" href="'.$url.'" rel="'.$relopt.'" title="'.$title.'::'.$name.'">';
         $html .= '</a></li>';
      }
      return $html;
   }

   /**
    * Helper function to build the Frontpage url. Not necessary on article pages
    *
    * @param object $article
    * @return string
    */
   function constructFrontpageUrl(&$article) {
      /*
       $needles = array(
       'article'  => (int) $article->slug,
       'category' => (int) $article->catslug,
       'section'  => (int) $article->sectionid
       );

       $link = 'index.php?option=com_content&view=article&id='. $article->slug;

       if($article->catslug) {
       $link .= '&catid='.$article->catslug;
       }

       if($item = ModAGSocialBookmarksHelper::_findItem($needles)) {
       $link .= '&Itemid='.$item->id;
       }
       */
      $link = 'index.php';
      return $link;
   }

   /**
    * Delete manual bookmark tag from Text
    *
    * @param string $article
    * @return string
    */
   function deleteBookmarkTag($text) {
      return str_replace('{sexybookmark}', '', $text);
   }

   /**
    * Delete inserted bookmark tag to avoid displaying
    * sexy bookmarks menu
    *
    * @param string $text
    * @return string
    */
   function deleteAntiBookmarkTag($text) {
      return str_replace('{nosexybookmark}', '', $text);
   }

   /**
    * Helper function to create short url's for Twitter
    *
    *
    * @param string $url
    * @return string
    */
   function getShortUrl($url,$params) {

      switch ($params->get('url_service')) {
         case 'tinyurl':
            $api_url = 'http://tinyurl.com/api-create.php?url='.$url;
            break;
         case 'is.gd':
            $api_url = 'http://is.gd/api.php?longurl='.$url;
            break;
         case 'rims':
            $api_url = 'http://ri.ms/api-create.php?url='.$url;
            break;
         case 'tinyarro':
            $api_url = 'http://tinyarro.ws/api-create.php?url='.$url;
            break;
      }

      $ch = curl_init();
      $timeout = 5;
      curl_setopt($ch,CURLOPT_URL,$api_url);
      curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
      curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
      $data = curl_exec($ch);
      curl_close($ch);
      return $data;
   }

   /**
    * Finds the Itemid for the correct Url on the frontpage
    *
    * @param array $needles
    * @return object
    */
   function _findItem($needles) {

      $component =& JComponentHelper::getComponent('com_content');
      $menus  = &JApplication::getMenu('site', array());
      $items  = $menus->getItems('componentid', $component->id);
      $match = null;

      foreach($needles as $needle => $id)
      {
         foreach($items as $item)
         {
            if ((@$item->query['view'] == $needle) && (@$item->query['id'] == $id)) {
               $match = $item;
               break;
            }
         }

         if(isset($match)) {
            break;
         }
      }

      return $match;
   }

} //end ModAGSocialBookmarksHelper

?>